#ifndef _SCHED_H_
#define _SCHED_H_

#include <type.h>
#include <system.h>

#define DEFAULT_STACK_SIZE 0x1000

void wait_sched();
void make_sched();
void init_sched();
#define __ switchnext();
void show_state(CPU_state *);
void init_thread(struct threadstate *state,void *args,unsigned long signal);
u32 create_thread(char *name,void *entry,void *args,unsigned long signal);
struct threadstate *state_create_thread(char *name,void *entry,void *args,unsigned long signal);
unsigned long get_thread_id(char *name);
int delete_thread(unsigned long id);
int end_all_threades();
void sleep_thread(unsigned long id);
void wake_thread(unsigned long id);
void temp_sleep_thread(unsigned long id);
void det_sleep_thread(unsigned long id,int count);
void dec_time(unsigned long id);
void inc_time(unsigned long id);
void default_time(unsigned long id);
void least_time(unsigned long id);
void idle_me(void (*fn)(void),unsigned long millisecs);
void wake_idle(unsigned long id);
void sleep();
void temp_sleep();
void det_sleep(int count);
unsigned long running_thread_id();
CPU_state *currentthread();
char *running_thread_name();
int scheduler_up();
void get_sched_time(u32 *t);
int add_pipe_thread(struct pipe *p);
int remove_pipe_thread(struct pipe *p);
void init_sched();

int wait_for_thread(unsigned long id);

void show_all_threades();
unsigned long get_my_pid();

#define STACK_SAFE 100
u32 allocate_thread_stack();
void exit(int errno);

void thread_send_signal(unsigned long pid,unsigned long signal);
void function_send_signal(void (*fn)(void *args,unsigned long signal),unsigned long signal);

#define AWAKE 0
#define SLEEP 1
#define TEMP_SLEEP 2
#define DET_SLEEP 3

#define THREAD_SIG_END 1
#define THREAD_SIG_PAUSING 2
#define THREAD_SIG_RESUMING 3
#define THREAD_SIG_TIMER 4

void list_threads();

#endif
